home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
245
/
growaray.doc
< prev
next >
Wrap
Text File
|
1988-02-07
|
2KB
|
36 lines
Growing Arrays
a somewhat strange technique
in GFA BASIC
by DAEDWARDS
Every now and then you need a really huge array, but you are
not certain just how big. This might occur in sorts, or when you
are processing text. Or consider a spreadsheet.
And there are tradeoffs - if you are processing a small text
file, you can really speed things up with a RAMdisk, but if the
file gets too big, you need that memory for processing. Or on a
spreadsheet - some spreadsheets are 200 rows of 20 columns, others
are 20 rows of 200 columns. How do you dimension the array?
There are all sorts of tricks to use to get out of this,
involving dynamic memory allocation and pointers, or doing a lot
of extra calculation yourself, but a way around it which I think
is unique to GFA Basic is to make the array grow in the desired
direction. Nothing changes except the size. It still has the same
name, you don't need to mess with pointers, and you can still
expect GFA Basic to do the work for you.
There is a minor catch - if you want lots of different arrays
to change size (they can, in theory, shrink as well as grow,
although I have never needed to shrink one), then you need a
separate routine for each variable type (integer, real, boolean,
or string) at each number of dimensions. In other words, the array
A$(X,Y), A$(X), and A(X) involve three different "grow" routines.
The GFA Basic program demonstrates the growth of a single-
dimensioned string array and a two-dimension array of real
numbers.